/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager.create;

import br.com.deployment.daoImpl.ExecutorDAOImpl;
import br.com.deployment.daoImpl.GroupsDAOImpl;
import br.com.deployment.entities.Executor;
import br.com.deployment.entities.Groups;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author ely
 */

@ManagedBean
@SessionScoped
public class ManagerCreateAcess {
    
    @EJB
    GroupsDAOImpl groupsService;
    
    @EJB
    ExecutorDAOImpl executorService;
    
    private Executor     executor;
    private List<Groups> lstGroups;
    private List<Groups> groups;
    
    public ManagerCreateAcess(){
        
    }
    
    public List<Groups> listAllGroups(){
        return lstGroups = groupsService.findAll();
    }
    
    public void update(){
        this.executor.setGroups(groups);
        executorService.update(this.executor);
    }
    
    // Mostra o Objeto Executor Selecionado e Redireciona para a página
    public void redirect(String string, Executor e) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            this.executor = e;
            groups = groupsService.findGoupsExecutor(this.executor);
            context.getExternalContext().redirect(string);
        } catch (IOException ex) {
            Logger.getLogger(ManagerCreateAcess.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Executor getExecutor() {
        return executor;
    }

    public void setExecutor(Executor executor) {
        this.executor = executor;
    }

    public List<Groups> getLstGroups() {
        return lstGroups;
    }

    public void setLstGroups(List<Groups> lstGroups) {
        this.lstGroups = lstGroups;
    }

    public List<Groups> getGroups() {
        return groups;
    }

    public void setGroups(List<Groups> groups) {
        this.groups = groups;
    }
    
    
    
}
